<template>
    <div>
        <h1>登录</h1>
        <h1>hyhgghghgh</h1>
        <table class="table">
            <tbody>
                <tr>
                    <td>登录名</td>
                    <td>
                        <input type="text" v-model="data.name" />
                    </td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td>
                        <input type="password" v-model="data.pwd" />
                    </td>
                </tr>
                <tr>
                    <td colspan="2">
                        <input type="button" value="登录" @click="login" />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from "axios";
import{ref } from "vue"
import { useRouter } from "vue-router";
import {useuserStore} from '../stores/user';
const router = useRouter();
const cc = useuserStore()
const data=ref({
    name : "",
    pwd : ""
})
const login = () => {

        if (data.value.name=="") {
            alert("登录名不能为空。。。");
            return;
        }
        if (data.value.pwd=="") {
            alert("密码不能为空。。。");
            return;
        }
    axios.get("/api/Car/Login", { params: data.value }).then(res => {
        if(res.data.Uname==-1)
        {
           alert("登录名重复");
           return;
        }
        if (res.data.Uid == -1) {
            alert("登录名错了。。。");
           
        }
        else if (res.data.Uid == -2) {
            alert("密码错了。");
          
        }
        else
        {
            alert("成功成功");
             cc.userdata.Uname = data.value.name
             cc.userdata.Pwd = data.value.pwd
             cc.userdata.islogin = true
             router.push("addcar");
        } 
        
    });
};
</script>

<style scoped></style>